﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="coupon.aspx.cs" Inherits="GgcmsTBK.coupon" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body {
  padding-top: 40px;
  padding-bottom: 40px;
  background-color: #eee;
}

.form-signin {
  max-width: 330px;
  padding: 15px;
  margin: 0 auto;
}
.form-signin .form-signin-heading,
.form-signin .checkbox {
  margin-bottom: 10px;
}
.form-signin .checkbox {
  font-weight: normal;
}
.form-signin .form-control {
  position: relative;
  height: auto;
  -webkit-box-sizing: border-box;
     -moz-box-sizing: border-box;
          box-sizing: border-box;
  padding: 10px;
  font-size: 16px;
}
.form-signin .form-control:focus {
  z-index: 2;
}
.form-signin input[type="email"] {
  margin-bottom: -1px;
  border-bottom-right-radius: 0;
  border-bottom-left-radius: 0;
}
.form-signin input[type="password"] {
  margin-bottom: 10px;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}
    </style>
    <script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
    <%if (mySet.logined)
        { %>
    <div class="container">

      <form class="form-signin" id="loginfrom">
        <h2 class="form-signin-heading">Please sign in</h2>
        <label for="inputEmail" class="sr-only">Email address</label>
        <input type="text" id="inputCode" class="form-control" placeholder="Email address" required autofocus>
        <label for="inputPassword" class="sr-only">Password</label>
        <input type="password" id="inputPassword" class="form-control" placeholder="Password" required>
        <div class="checkbox">
            <img src="" alt="" id="captcha" />
        </div>
        <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
      </form>

    </div> <!-- /container -->
    <script>
        $(function () {
            $("#captcha").attr("src", getCaptcha());
            $("#captcha").click(x=> {
                $("#captcha").attr("src", getCaptcha());
            });
            $("#loginfrom").submit((e, n) => {
                e.preventDefault();
                e.stopPropagation();
                var code = $("#inputCode").val();
                var pass = $("#inputPassword").val();
                var formData = new FormData();
                formData.append("code", code);
                formData.append("pass", pass);
                formData.append("type", "login");
                fetch("coupon.aspx", { method: 'post', body: formData }).then(x=>x.json()).then(x=> {
                    if (x.code == 0) {
                        alert("ok");
                        location.reload();
                    } else {
                        alert("error");
                    }
                });
            });
        });
        function getCaptcha() {
            var rnd = (new Date()).getTime();
            var url = "captcha.aspx?rnd=r_" + rnd;
            return url;
        }
    </script>
    <%}
        else
        { %>

    <div class="container">

      <form class="form-signin" id="filefrom">
        <h2 class="form-signin-heading">Please sign in</h2>
        <label for="inputFile" class="sr-only">Email address</label>
        <input type="file" name="inputFile" id="inputFile" class="form-control"  required autofocus>
        <label for="inputPassword" class="sr-only">Password</label>
        <input type="password" name="inputPassword" id="inputPassword" class="form-control" placeholder="Password" required>
        <input type="hidden" name="type"  />
        <button class="btn btn-lg btn-primary btn-block" type="button" id="btn_upload">上传</button>
          <button class="btn btn-lg btn-primary btn-block" type="button" id="btn_clear">清理</button>
          <button class="btn btn-lg btn-primary btn-block" type="button" id="btn_update">更新</button>
      </form>

    </div> <!-- /container -->
    <script>
        $(function () {
            $("#btn_upload").click((e) => {
                e.preventDefault();
                e.stopPropagation();
                var file = $("#inputFile").get(0).files[0];
                var pass = $("#inputPassword").val();
                var formData = new FormData();
                formData.append("file", file);
                formData.append("pass", pass);
                formData.append("type", "file");
                fetch("coupon.aspx", { method: 'post', body: formData }).then(x=>x.json()).then(x=> {
                    if (x.code == 0) {
                        alert("ok");
                    } else {
                        alert("error");
                    }
                });
            });
            $("#btn_clear").click((e) => {
                e.preventDefault();
                e.stopPropagation();
                var pass = $("#inputPassword").val();
                fetch("./?qtype=clear&safekey=" + pass, { method: 'get' }).then(x=>x.json()).then(x=> {
                    if (x.code == 0) {
                        alert("ok:" + x.result);
                    } else {
                        alert("error:" + x.message);
                    }
                });
            });
            $("#btn_update").click((e) => {
                e.preventDefault();
                e.stopPropagation();
                var pass = $("#inputPassword").val();
                fetch("./?qtype=update&safekey=" + pass, { method: 'get' }).then(x=>x.json()).then(x=> {
                    console.log(x);
                    if (x.code == 0) {
                        alert("ok");
                    } else {
                        alert("error:" + x.message);
                    }
                });
            });
        });

    </script>
    <%} %>
</body>
</html>
